package com.ruoyi.web.controller.product;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.HhSize;
import com.ruoyi.system.service.IHhSizeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品规格Controller
 * 
 * @author ruoyi
 * @date 2021-06-16
 */
@RestController
@RequestMapping("/product/size")
public class HhSizeController extends BaseController
{
    @Autowired
    private IHhSizeService hhSizeService;

    /**
     * 查询商品规格列表
     */
    @PreAuthorize("@ss.hasPermi('product:size:list')")
    @GetMapping("/list")
    public TableDataInfo list(HhSize hhSize)
    {
        startPage();
        List<HhSize> list = hhSizeService.selectHhSizeList(hhSize);
        return getDataTable(list);
    }

    /**
     * 导出商品规格列表
     */
    @PreAuthorize("@ss.hasPermi('product:size:export')")
    @Log(title = "商品规格", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HhSize hhSize)
    {
        List<HhSize> list = hhSizeService.selectHhSizeList(hhSize);
        ExcelUtil<HhSize> util = new ExcelUtil<HhSize>(HhSize.class);
        return util.exportExcel(list, "商品规格");
    }

    /**
     * 获取商品规格详细信息
     */
    @PreAuthorize("@ss.hasPermi('product:size:query')")
    @GetMapping(value = "/{sizeId}")
    public AjaxResult getInfo(@PathVariable("sizeId") Long sizeId)
    {
        return AjaxResult.success(hhSizeService.selectHhSizeById(sizeId));
    }

    /**
     * 新增商品规格
     */
    @PreAuthorize("@ss.hasPermi('product:size:add')")
    @Log(title = "商品规格", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HhSize hhSize)
    {
        int flag = hhSizeService.insertHhSize(hhSize);
        if (flag<=0){
            return AjaxResult.error("操作失败，没有相应类型的商品");
        }
        return toAjax(flag);
    }

    /**
     * 修改商品规格
     */
    @PreAuthorize("@ss.hasPermi('product:size:edit')")
    @Log(title = "商品规格", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HhSize hhSize)
    {
        int flag = hhSizeService.updateHhSize(hhSize);
        if (flag<=0){
            return AjaxResult.error("操作失败，没有相应类型的商品");
        }
        return toAjax(flag);
    }

    /**
     * 删除商品规格
     */
    @PreAuthorize("@ss.hasPermi('product:size:remove')")
    @Log(title = "商品规格", businessType = BusinessType.DELETE)
	@DeleteMapping("/{sizeIds}")
    public AjaxResult remove(@PathVariable Long[] sizeIds)
    {
        return toAjax(hhSizeService.deleteHhSizeByIds(sizeIds));
    }
}
